package com.nft.po;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

@Data
@ApiModel("分页返回构造器")
public class CommonPage<T> {
    @ApiModelProperty("数据")
    private List<T> list;

    @ApiModelProperty("总记录数")
    private long total;

    @ApiModelProperty("总页数")
    private long totalPage;

    /**
     * 构建
     * @return
     */
    public static<T> CommonPage<T> builder(IPage<T> data){
        CommonPage commonPage=new CommonPage();
        commonPage.setList(data.getRecords());
        commonPage.setTotalPage(data.getPages());
        commonPage.setTotal(data.getTotal());
        return commonPage;
    }

}
